home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <time.h>
- #include <sys/time.h>
- #include "DayView.h"
- #include "VCal.h"
- #include "Info.h"
- #include "Entry.h"
- #include "EntryDialog.h"
- #include "Utils.h"
- #include "Preferences.h"
-
- #include <Vk/VkScroll.h>
- #include <Vk/VkResource.h>
- #include <Vk/VkSubMenu.h>
- #include <Vk/VkRepeatButton.h>
- #include <Vk/VkMenu.h>
- #include <Vk/VkMenuBar.h>
- #include <Vk/VkMenuItem.h>
- #include <Vk/VkPopupMenu.h>
- #include <Vk/VkQuestionDialog.h>
- #include <Vk/VkHelpPane.h>
-
- #include <Xm/Form.h>
- #include <Xm/Label.h>
- #include <Xm/ToggleBG.h>
- #include <Xm/RowColumn.h>
- #include <Xm/PushBG.h>
-
- static Arg args[10];
- static int count;
-
- void
- DayView::quit_menu(Widget, XtPointer client_data, XtPointer)
- {
- DayView *obj = (DayView *) client_data;
-
- obj->doQuit();
- }
-
- void
- DayView::restricted_menu(Widget w, XtPointer client_data, XtPointer)
- {
- DayView *obj = (DayView *) client_data;
-
- obj->restrictedChanged(XmToggleButtonGadgetGetState(w));
- }
-
- void
- DayView::day_select(Widget, XtPointer client_data, XEvent *event)
- {
- DayView *obj = (DayView *) client_data;
-
- if (event->xbutton.button == 1) {
- obj->displayToday();
- }
- }
-
- void
- DayView::weekday_menu(Widget, XtPointer client_data, XtPointer)
- {
- VkCallbackStruct *cb = (VkCallbackStruct *) client_data;
- DayView *obj = (DayView *) cb->obj;
- int weekday = (int) cb->client_data;
-
- obj->selectWeekday(weekday);
- }
-
- void
- DayView::entry_stub(Widget w, XtPointer client_data, XtPointer call_data)
- {
- DayView *obj = (DayView *) client_data;
- TimeEntryCallback *cb = (TimeEntryCallback *) call_data;
-
- obj->entryCallback(w, cb);
- }
-
- void
- DayView::grid_stub(Widget, XtPointer client_data, XtPointer call_data)
- {
- DayView *obj = (DayView *) client_data;
- TimeGridCallback *cb = (TimeGridCallback *) call_data;
-
- obj->gridCallback(cb);
- }
-
- void
- DayView::attributes_menu(Widget, XtPointer client_data, XtPointer)
- {
- DayView *obj = (DayView *) client_data;
-
- obj->entryDialog(obj->menuEntry);
- }
-
- void
- DayView::delete_menu(Widget, XtPointer client_data, XtPointer)
- {
- DayView *obj = (DayView *) client_data;
-
- obj->deleteEntry(obj->menuEntry);
- obj->scroll->reannotateScrollBar();
- }
-
- Boolean
- DayView::reset_state(XtPointer client_data)
- {
- DayView *obj = (DayView *) client_data;
-
- obj->owner->selectDay(obj->_day, obj->_month, obj->_year);
- return True;
- }
-
- void
- DayView::save_text(Widget, XtPointer client_data, XtPointer)
- {
- DayView *obj = (DayView *) client_data;
-
- obj->owner->saveAsTextMenu(True, obj, obj->_day, obj->_month, obj->_year);
- }
-
- void
- DayView::display_overview(Widget, XtPointer client_data, XtPointer)
- {
- DayView *obj = (DayView *) client_data;
-
- obj->owner->displayWeekOverview();
- }
-
- void
- DayView::entry_attributes(Widget, XtPointer client_data, XtPointer)
- {
- DayView *obj = (DayView *) client_data;
-
- obj->entryAttributesMenu();
- }
-
- void
- DayView::entry_delete(Widget, XtPointer client_data, XtPointer)
- {
- DayView *obj = (DayView *) client_data;
-
- obj->entryDeleteMenu();
- }
-
- /**********************************************************************/
-
- void
- DayView::selectDate(int d, int m, int y, MemoryInfo *i, RepeatingEntry *r)
- {
- // if (_day != d || _month != m || _year != y) {
- grid->reset();
- eraseEntries();
- _day = d;
- _month = m;
- _year = y;
- updateHeader();
- // So that the header changes immediately, while we change each of the
- // fields...
- XmUpdateDisplay(header);
- _info = i;
- _repeating = r;
- initEntries();
- displayEntries();
- updateTime();
- // }
- }
-
- void
- DayView::unselect()
- {
- grid->reset();
- eraseEntries();
- _day = _month = _year = 0;
- _info = NULL;
- _repeating = NULL;
- }
-
- void
- DayView::entryChanged(EntryDialog *dialog)
- {
- Entry *dentry, *entry;
- VkQuestionDialog *d;
-
- dentry = dialog->entry();
- entry = findDialogEntry(dialog);
- if (d = (VkQuestionDialog *) entry->alarmInfo()->alarm) {
- delete d;
- entry->alarmInfo()->alarm = NULL;
- }
- if (entry != dentry) {
- removeEntry(entry);
- addEntry(dentry);
- dentry->setData(entry->data());
- notifyOwner(dentry, entry);
- delete entry;
- } else {
- notifyOwner(dentry);
- }
- if (dentry->repeating() &&
- !((RepeatingEntry *) dentry)->repeatApplies(_day, _month, _year)) {
- scheduleResetState();
- }
- }
-
- int
- DayView::eraseEntry(Entry *entry)
- {
- DayViewInfo *info;
-
- info = (DayViewInfo *) entry->data();
- if (info) {
- delete info->time;
- if (info->dialog) {
- delete info->dialog;
- }
- delete info;
- entry->setData(NULL);
- return 1;
- } else {
- return 0;
- }
- }
-
- void
- DayView::updateTime()
- {
- struct timeval t;
- struct tm *now;
-
- gettimeofday(&t, NULL);
- now = localtime(&t.tv_sec);
- if (_day != now->tm_mday ||
- _month != now->tm_mon+1 ||
- _year != now->tm_year+1900) {
- _lastTime = -1;
- grid->hideCurrentTime();
- } else {
- _lastTime = now->tm_hour*60+now->tm_min;
- grid->showCurrentTime(_lastTime);
- }
- scroll->reannotateScrollBar();
- }
-
- void
- DayView::scrollToCurrentTime()
- {
- struct timeval t;
- struct tm *now;
-
- gettimeofday(&t, NULL);
- now = localtime(&t.tv_sec);
- if (_day == now->tm_mday ||
- _month == now->tm_mon+1 ||
- _year == now->tm_year+1900) {
- scrollToTime(now->tm_hour*60+now->tm_min);
- }
- }
-
- void
- DayView::scrollToBeginning()
- {
- scroll->setScrollPos(0);
- }
-
- void
- DayView::scrollToTime(int time)
- {
- int start, length, value, maximum, clipv;
- int timev, destv;
-
- start = grid->getStart();
- length = grid->getLength();
- if (time >= start && time < start+length) {
- count = 0;
- XtSetArg(args[count], XmNmaximum, &maximum); count++;
- XtSetArg(args[count], XmNvalue, &value); count++;
- XtSetArg(args[count], XmNsliderSize, &clipv); count++;
- XtGetValues(scroll->getScrollBar(), args, count);
-
- timev = ((time-start)*maximum)/length;
- if (timev < value || timev >= value+clipv) {
- destv = timev-clipv/2;
- if (destv+clipv >= maximum) {
- destv = maximum-clipv-1;
- }
- if (destv < 0) {
- destv = 0;
- }
- scroll->setScrollPos(destv);
- }
- }
- }
-
- /**********************************************************************/
-
- Widget
- DayView::setUpInterface(Widget parent)
- {
- fileMenu();
- displayMenu();
- entryMenu();
- if (menu()->helpPane()) {
- menu()->helpPane()->setItemSensitivities(False, True, False, False,
- False);
- }
-
- entryPopup = new VkPopupMenu();
- entryPopup->addLabel("entryPopup");
- entryPopup->addSeparator();
- entryPopup->addAction("entryMenuAttributes", DayView::attributes_menu,
- (XtPointer) this);
- entryPopup->addAction("entryMenuDelete", DayView::delete_menu,
- (XtPointer) this);
- entryPopup->build(parent);
- repeatingEntryPopup = new VkPopupMenu();
- repeatingEntryPopup->addLabel("repeatingEntryPopup");
- repeatingEntryPopup->addSeparator();
- repeatingEntryPopup->addAction("repeatingEntryMenuAttributes",
- DayView::attributes_menu,
- (XtPointer) this);
- repeatingEntryPopup->addAction("repeatingEntryMenuDelete",
- DayView::delete_menu,
- (XtPointer) this);
- repeatingEntryPopup->build(parent);
- count = 0;
- XtSetArg(args[count], XmNpopupEnabled, False); count++;
- XtSetValues(entryPopup->baseWidget(), args, count);
- XtSetValues(repeatingEntryPopup->baseWidget(), args, count);
-
- count = 0;
- form = XmCreateForm(parent, "dayViewForm", args, count);
-
- scroll = new VkScroll("scroll", form);
- VkAddCallbackMethod(VkScroll::scrollCallback, scroll, this,
- DayView::scrollProc, NULL);
- scroll->setAnnotations();
-
- dayPrev = new VkRepeatButton("dayPrev", form, RB_arrowButtonGadget);
- count = 0;
- XtSetArg(args[count], XmNtopAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM); count++;
- XtSetValues(dayPrev->baseWidget(), args, count);
- dayPrev->show();
- VkAddCallbackMethod(VkRepeatButton::buttonCallback, dayPrev, this,
- DayView::doDayPrev, NULL);
-
- dayNext = new VkRepeatButton("dayNext", form, RB_arrowButtonGadget);
-
- count = 0;
- XtSetArg(args[count], XmNtopAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM); count++;
- XtSetValues(dayNext->baseWidget(), args, count);
- dayNext->show();
- VkAddCallbackMethod(VkRepeatButton::buttonCallback, dayNext, this,
- DayView::doDayNext, NULL);
-
- count = 0;
- XtSetArg(args[count], XmNtopAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNleftAttachment, XmATTACH_WIDGET); count++;
- XtSetArg(args[count], XmNleftWidget, dayPrev->baseWidget()); count++;
- XtSetArg(args[count], XmNrightAttachment, XmATTACH_WIDGET); count++;
- XtSetArg(args[count], XmNrightWidget, dayNext->baseWidget()); count++;
- XtSetArg(args[count], XmNbottomAttachment,
- XmATTACH_OPPOSITE_WIDGET); count++;
- XtSetArg(args[count], XmNbottomWidget, dayPrev->baseWidget()); count++;
- header = XmCreateLabel(form, "header", args, count);
- XtManageChild(header);
- XtAddEventHandler(header, ButtonPressMask, False,
- (XtEventHandler) DayView::day_select,
- (XtPointer) this);
-
- count = 0;
- XtSetArg(args[count], XmNtopAttachment, XmATTACH_WIDGET); count++;
- XtSetArg(args[count], XmNtopWidget, header); count++;
- XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNbottomAttachment, XmATTACH_FORM); count++;
- XtSetValues(scroll->baseWidget(), args, count);
-
- if (restricted) {
- grid = new TimeGrid("timeGrid", scroll->getClip(), True,
- timeInterval, subdivisions,
- restrictStart, restrictEnd-restrictStart);
- } else {
- grid = new TimeGrid("timeGrid", scroll->getClip());
- }
- grid->setCallback(DayView::grid_stub, (XtPointer) this);
- count = 0;
- XtSetArg(args[count], XmNtopAttachment, XmATTACH_NONE); count++;
- XtSetArg(args[count], XmNbottomAttachment, XmATTACH_NONE); count++;
- XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM); count++;
- XtSetValues(grid->baseWidget(), args, count);
- scroll->setChild(grid->baseWidget());
- grid->show();
-
- XtManageChild(form);
- return form;
- }
-
- void
- DayView::handleWmDeleteMessage()
- {
- doQuit();
- }
-
- void
- DayView::fileMenu()
- {
- VkSubMenu* menu = addMenuPane("dayFileMenu");
- VkMenuToggle *item;
-
- item = menu->addToggle("restrictedToggleMenuItem",
- DayView::restricted_menu,
- (XtPointer) this);
- item->setVisualState(thePreferences->restricted());
- menu->addSeparator();
- menu->addAction("dayQuitMenuItem",
- DayView::quit_menu,
- (XtPointer) this);
- }
-
- void
- DayView::displayMenu()
- {
- VkSubMenu* menu = addMenuPane("displayMenu");
-
- weekdayMenu(menu);
- menu->addAction("weekOverviewMenuItem",
- DayView::display_overview,
- (XtPointer) this);
- menu->addAction("saveAsTextMenuItem",
- DayView::save_text,
- (XtPointer) this);
- }
-
- void
- DayView::entryMenu()
- {
- VkSubMenu* menu = addMenuPane("entryMenu");
-
- entryAttrItem = menu->addAction("entryItemAttributes",
- DayView::entry_attributes,
- (XtPointer) this);
- entryDeleteItem = menu->addAction("entryItemDelete",
- DayView::entry_delete,
- (XtPointer) this);
- entryDeleteEverywhereItem = menu->addAction("entryItemDeleteEverywhere",
- DayView::entry_delete,
- (XtPointer) this);
-
- setMenuEntry(NULL);
- }
-
- void
- DayView::updateHeader()
- {
- int weekday;
- XmString xs;
- char str[256];
-
- weekday = computeWeekday(_day, _month, _year);
- formatDate(weekday, _day, _month, _year, str);
- xs = XmStringCreateSimple(str);
- count = 0;
- XtSetArg(args[count], XmNlabelString, xs); count++;
- XtSetValues(header, args, count);
- XmStringFree(xs);
- }
-
- void
- DayView::initialExpose()
- {
- count = 0;
- XtSetArg(args[count], XmNincrement,
- grid->getSlotHeight()*grid->getSubDiv()); count++;
- XtSetValues(scroll->getScrollBar(), args, count);
- updateTime();
- }
-
- void
- DayView::restrictedChanged(Boolean r)
- {
- if (restricted != r) {
- theApplication->busy();
- restricted = r;
- hideEntries();
- if (restricted) {
- grid->changeDuration(restrictStart, restrictEnd-restrictStart);
- } else {
- grid->changeDuration(0, MINS_IN_DAY);
- }
- displayEntries();
- updateTime();
- scroll->recomputeScrollBar();
- scrollToCurrentTime();
- theApplication->notBusy();
- }
- }
-
- void
- DayView::notifyOwner(Entry *entry, Entry *oldEntry)
- {
- struct timeval t;
- struct tm *now;
-
- gettimeofday(&t, NULL);
- now = localtime(&t.tv_sec);
- entry->setAlarmFired(entry->start() < now->tm_hour*60+now->tm_min,
- ALL_NOTIFICATIONS);
- owner->dayViewChanged(this, entry, oldEntry);
- setMenuEntry(lastMenuEntry);
- }
-
- void
- DayView::scrollProc(Widget, XtPointer, XtPointer call_data)
- {
- VkScrollCallback *cb = (VkScrollCallback *) call_data;
-
- switch (cb->reason) {
- case VS_initialExpose:
- initialExpose();
- break;
- case VS_resize:
- // Make the grid reconfigure first
- grid->reconfig();
- displayEntries();
- break;
- case VS_troughPixmap:
- drawTrough(cb);
- break;
- case VS_none:
- default:
- break;
- }
- }
-
- void
- DayView::drawTrough(VkScrollCallback *cb)
- {
- XGCValues gcv;
- Entry *entry;
- RepeatingEntry *rentry;
- Pixel fg;
- int start, length, h;
-
- if (troughGC == NULL) {
- count = 0;
- XtSetArg(args[count], XmNforeground, &fg); count++;
- XtGetValues(header, args, count);
- gcv.function = GXcopy;
- gcv.foreground = fg;
- gcv.background = owner->annotateColor();
- gcv.stipple = owner->getTile();
- gcv.fill_style = FillOpaqueStippled;
- troughGC = XtGetGC(form,
- GCFunction | GCForeground | GCBackground |
- GCStipple | GCFillStyle,
- &gcv);
- }
- if (timeGC == NULL && header) {
- count = 0;
- XtSetArg(args[count], XmNforeground, &fg); count++;
- XtGetValues(header, args, count);
- gcv.function = GXcopy;
- gcv.foreground = fg;
- timeGC = XtGetGC(form,
- GCFunction | GCForeground,
- &gcv);
- }
-
- if (_repeating) {
- rentry = _repeating;
- while (rentry->next()) {
- rentry = rentry->next();
- if (rentry->repeatApplies(_day, _month, _year)) {
- annotateEntry(rentry, cb->width, cb->height, cb->pixmap);
- }
- }
- }
- if (_info) {
- _info->rewind();
- while (entry = _info->nextEntry()) {
- annotateEntry(entry, cb->width, cb->height, cb->pixmap);
- }
- }
- if (timeGC && _lastTime > -1) {
- start = grid->getStart();
- length = grid->getLength();
- if (_lastTime >= start && _lastTime < start+length) {
- h = ((_lastTime-start)*cb->height)/length;
- if (h > 3) {
- h -= 1;
- }
- XFillRectangle(XtDisplay(_baseWidget), cb->pixmap, timeGC,
- 0, h, cb->width, 1);
- }
- }
- }
-
- void
- DayView::annotateEntry(Entry *entry, int width, int height, Pixmap pixmap)
- {
- DayViewInfo *info;
- Position y;
- Dimension height2;
- int h;
-
- info = (DayViewInfo *) entry->data();
- if (info && XtIsManaged(info->time->baseWidget())) {
- count = 0;
- XtSetArg(args[count], XmNy, &y); count++;
- XtSetArg(args[count], XmNheight, &height2); count++;
- XtGetValues(info->time->baseWidget(), args, count);
- h = ((int) height2*height)/grid->getHeight();
- if (h > 3) {
- h -= 1;
- }
- XFillRectangle(XtDisplay(_baseWidget), pixmap, troughGC,
- 0, ((int) y*height)/grid->getHeight(),
- width, h);
- }
- }
-
- void
- DayView::doDayPrev(Widget, XtPointer, XtPointer)
- {
- if (_day > 1) {
- owner->selectDay(_day-1, _month, _year);
- } else if (_month > 1) {
- owner->selectDay(NumberOfDays(_month-1, _year), _month-1, _year);
- } else {
- owner->selectDay(NumberOfDays(12, _year), 12, _year-1);
- }
- }
-
- void
- DayView::doDayNext(Widget, XtPointer, XtPointer)
- {
- if (_day < NumberOfDays(_month, _year)) {
- owner->selectDay(_day+1, _month, _year);
- } else if (_month < 12) {
- owner->selectDay(1, _month+1, _year);
- } else {
- owner->selectDay(1, 1, _year+1);
- }
- }
-
- void
- DayView::displayToday()
- {
- owner->selectToday();
- scrollToCurrentTime();
- }
-
- void
- DayView::weekdayMenu(VkMenu *parent)
- {
- int each;
- VkCallbackStruct *callbackStructs;
- VkSubMenu *menu = parent->addSubmenu("weekdayMenu");
-
- callbackStructs = new VkCallbackStruct[DAYS_IN_WEEK]; // memory leak
- for (each=0; each<DAYS_IN_WEEK; each++) {
- callbackStructs[each].obj = this;
- callbackStructs[each].client_data = (void *) (each+1);
- menu->addAction(weekdayString(each+1), DayView::weekday_menu,
- (XtPointer) &callbackStructs[each]);
- }
- }
-
- void
- DayView::selectWeekday(int day)
- {
- int each, num, delta, wday;
-
- wday = computeWeekday(_day, _month, _year);
- if (day == wday) {
- return;
- } else if (day > wday) {
- delta = 1;
- num = day-wday;
- } else {
- delta = -1;
- num = wday - day;
- }
- for (each=0; each<num; each++) {
- _day = _day+delta;
- if (!_day) {
- if (_month > 1) {
- _month--;
- _day = NumberOfDays(_month, _year);
- } else {
- _year--;
- _month = 12;
- _day = NumberOfDays(_month, _year);
- }
- } else if (_day > NumberOfDays(_month, _year)) {
- _day = 1;
- if (_month < 12) {
- _month++;
- } else {
- _year++;
- _month = 1;
- }
- }
- }
- owner->selectDay(_day, _month, _year);
- }
-
- void
- DayView::initEntries()
- {
- Entry *entry;
- RepeatingEntry *rentry;
-
- if (_repeating) {
- rentry = _repeating;
- while (rentry->next()) {
- rentry = rentry->next();
- if (rentry->repeatApplies(_day, _month, _year)) {
- initEntry(rentry);
- }
- }
- }
- if (_info) {
- _info->rewind();
- while (entry = _info->nextEntry()) {
- initEntry(entry);
- }
- }
- }
-
- void
- DayView::displayEntries()
- {
- Entry *entry;
- RepeatingEntry *rentry;
-
- if (_repeating) {
- rentry = _repeating;
- while (rentry->next()) {
- rentry = rentry->next();
- if (rentry->repeatApplies(_day, _month, _year)) {
- displayEntry(rentry);
- }
- }
- }
- if (_info) {
- _info->rewind();
- while (entry = _info->nextEntry()) {
- displayEntry(entry);
- }
- }
- scroll->reannotateScrollBar();
- }
-
- void
- DayView::hideEntries()
- {
- Entry *entry;
- RepeatingEntry *rentry;
-
- if (_repeating) {
- rentry = _repeating;
- while (rentry->next()) {
- rentry = rentry->next();
- if (rentry->repeatApplies(_day, _month, _year)) {
- hideEntry(rentry);
- }
- }
- }
- if (_info) {
- _info->rewind();
- while (entry = _info->nextEntry()) {
- hideEntry(entry);
- }
- }
- scroll->reannotateScrollBar();
- }
-
- void
- DayView::eraseEntries()
- {
- Entry *entry;
- RepeatingEntry *rentry;
-
- if (_repeating) {
- rentry = _repeating;
- while (rentry->next()) {
- rentry = rentry->next();
- // So we erase repeating entries that no longer apply
- // if (rentry->repeatApplies(_day, _month, _year)) {
- eraseEntry(rentry);
- // }
- }
- }
- if (_info) {
- _info->rewind();
- while (entry = _info->nextEntry()) {
- eraseEntry(entry);
- }
- }
- }
-
- void
- DayView::initEntry(Entry *entry)
- {
- DayViewInfo *info;
-
- info = new DayViewInfo;
- info->dialog = NULL;
- info->time = new TimeEntry("timeEntry", grid);
- info->time->setCallback(DayView::entry_stub, (XtPointer) this);
- entry->setData(info);
- }
-
- void
- DayView::displayEntry(Entry *entry)
- {
- DayViewInfo *info;
-
- info = (DayViewInfo *) entry->data();
- info->time->setText(entry->text());
- if (info->time->setTimeInterval(entry->start(), entry->length())) {
- info->time->show();
- }
- }
-
- void
- DayView::hideEntry(Entry *entry)
- {
- DayViewInfo *info;
-
- info = (DayViewInfo *) entry->data();
- info->time->hide();
- }
-
- void
- DayView::entryCallback(Widget w, TimeEntryCallback *cb)
- {
- switch (cb->reason) {
- case TE_textChanged:
- case TE_timeChanged:
- entryModified(findEntry(w), cb->reason);
- break;
- case TE_postMenu:
- if (menuEntry = findEntry(w)) {
- if (menuEntry->repeating()) {
- XmMenuPosition(repeatingEntryPopup->baseWidget(), &cb->event->xbutton);
- XtManageChild(repeatingEntryPopup->baseWidget());
- } else {
- XmMenuPosition(entryPopup->baseWidget(), &cb->event->xbutton);
- XtManageChild(entryPopup->baseWidget());
- }
- }
- break;
- case TE_deselect:
- if (cb->obj == lastMenuEntry) {
- setMenuEntry(NULL);
- }
- grid->reset();
- break;
- case TE_selected:
- setMenuEntry(cb->obj);
- case TE_none:
- break;
- }
- }
-
- Entry *
- DayView::findEntry(Widget w)
- {
- DayViewInfo *info;
- Entry *entry;
- RepeatingEntry *rentry;
-
- if (_repeating) {
- rentry = _repeating;
- while (rentry->next()) {
- rentry = rentry->next();
- // In case we modify entry attr so that the entry doesn't apply anymore
- // if (rentry->repeatApplies(_day, _month, _year)) {
- info = (DayViewInfo *) rentry->data();
- if (info && info->time->baseWidget() == w) {
- return rentry;
- }
- // }
- }
- }
- if (_info) {
- _info->rewind();
- while (entry = _info->nextEntry()) {
- info = (DayViewInfo *) entry->data();
- if (info->time->baseWidget() == w) {
- return entry;
- }
- }
- }
- return NULL;
- }
-
- void
- DayView::entryModified(Entry *entry, TimeEntryReason reason)
- {
- DayViewInfo *info;
- char *str;
-
- info = (DayViewInfo *) entry->data();
- if (reason == TE_timeChanged) {
- entry->setTime(info->time->start(), info->time->length());
- }
- if (reason == TE_textChanged || reason == TE_timeChanged) {
- str = info->time->getText();
- entry->setText(str);
- if (strlen(str)) {
- notifyOwner(entry);
- } else if (reason == TE_textChanged) {
- deleteEntry(entry);
- }
- XtFree(str);
- }
- scroll->reannotateScrollBar();
- }
-
- void
- DayView::deleteEntry(Entry *entry)
- {
- DayViewInfo *info;
- VkQuestionDialog *dialog;
-
- info = (DayViewInfo *) entry->data();
- removeEntry(entry);
- if (info->dialog) {
- delete info->dialog;
- }
- delete info->time;
- delete info;
- if (dialog = (VkQuestionDialog *) entry->alarmInfo()->alarm) {
- delete dialog;
- entry->alarmInfo()->alarm = NULL;
- }
- notifyOwner(entry);
- delete entry;
- }
-
- void
- DayView::doQuit()
- {
- grid->reset();
- eraseEntries();
- _day = _month = _year = 0;
- owner->deleteDayView(this);
- }
-
- void
- DayView::gridCallback(TimeGridCallback *cb)
- {
- Entry *entry;
- int start, last;
-
- switch (cb->reason) {
- case TG_requestNew:
- start = timeSlotSnap*(cb->value/timeSlotSnap);
- if (restricted) {
- last = restrictEnd;
- } else {
- last = MINS_IN_DAY;
- }
- if (start+defaultLength > last) {
- start = last-defaultLength;
- }
- entry = createEntry(start, defaultLength);
- displayEntry(entry);
- selectEntry(entry, True);
- scroll->reannotateScrollBar();
- break;
- case TG_deselect:
- grid->reset();
- setMenuEntry(NULL);
- break;
- case TG_none:
- break;
- }
- }
-
- Entry *
- DayView::createEntry(int start, int length)
- {
- Entry *entry;
-
- entry = new Entry();
- entry->setDate(_day, _month, _year);
- entry->setTime(start, length);
- entry->setNotifyPopup(thePreferences->notifyPopup());
- entry->setNotifyBell(thePreferences->notifyBell());
- entry->setNotifyMail(thePreferences->notifyMail());
- entry->setNotifyCommand(thePreferences->notifyCommand());
- entry->setAlarmAdvance(thePreferences->advanceWarning());
- entry->setAnnotate(thePreferences->annotateDay());
- addEntry(entry);
- initEntry(entry);
- notifyOwner(entry);
- return entry;
- }
-
- void
- DayView::selectEntry(Entry *entry, Boolean makeModified)
- {
- DayViewInfo *info;
-
- info = (DayViewInfo *) entry->data();
- info->time->select(makeModified);
- }
-
- void
- DayView::entryDialog(Entry *entry)
- {
- DayViewInfo *info;
-
- info = (DayViewInfo *) entry->data();
- if (info->dialog) {
- info->dialog->show();
- } else {
- theApplication->busy();
- info->dialog = new EntryDialog(entry, this, "entryDialog");
- info->dialog->post(NULL, NULL, NULL, NULL, NULL, "entryAttrDialog");
- theApplication->notBusy();
- }
- }
-
- Entry *
- DayView::findDialogEntry(EntryDialog *dialog)
- {
- Entry *entry;
- RepeatingEntry *rentry;
- DayViewInfo *info;
-
- if (_repeating) {
- rentry = _repeating;
- while (rentry->next()) {
- rentry = rentry->next();
- // In case we modify entry attr so that the entry doesn't apply anymore
- // if (rentry->repeatApplies(_day, _month, _year)) {
- info = (DayViewInfo *) rentry->data();
- if (info && info->dialog == dialog) {
- return rentry;
- }
- // }
- }
- }
- if (_info) {
- _info->rewind();
- while (entry = _info->nextEntry()) {
- info = (DayViewInfo *) entry->data();
- if (info->dialog == dialog) {
- return entry;
- }
- }
- }
- return NULL;
- }
-
- void
- DayView::removeEntry(Entry *entry)
- {
- if (entry->repeating()) {
- owner->removeRepeatingEntry((RepeatingEntry *) entry);
- } else {
- _info->removeEntry(entry);
- }
- }
-
- void
- DayView::addEntry(Entry *entry)
- {
- struct timeval t;
- struct tm *now;
-
- gettimeofday(&t, NULL);
- now = localtime(&t.tv_sec);
- entry->setAlarmFired(entry->start() < now->tm_hour*60+now->tm_min,
- ALL_NOTIFICATIONS);
- if (entry->repeating()) {
- gettimeofday(&t, NULL);
- now = localtime(&t.tv_sec);
- owner->addRepeatingEntry((RepeatingEntry *) entry);
- } else {
- _info->addEntry(entry);
- }
- }
-
- void
- DayView::scheduleResetState()
- {
- XtAppAddWorkProc(theApplication->appContext(),
- DayView::reset_state, (XtPointer) this);
- }
-
- void
- DayView::setMenuEntry(TimeEntry *entry)
- {
- Entry *e;
-
- lastMenuEntry = entry;
- if (lastMenuEntry &&
- (e = findEntry(entry->baseWidget()))) {
- entryAttrItem->activate();
- if (e->repeating()) {
- entryDeleteItem->hide();
- entryDeleteEverywhereItem->show();
- entryDeleteEverywhereItem->activate();
- } else {
- entryDeleteEverywhereItem->hide();
- entryDeleteItem->show();
- entryDeleteItem->activate();
- }
- } else {
- entryAttrItem->deactivate();
- entryDeleteEverywhereItem->hide();
- entryDeleteItem->show();
- entryDeleteItem->deactivate();
- }
- }
-
- void
- DayView::entryAttributesMenu()
- {
- Entry *e;
-
- if (lastMenuEntry &&
- (e = findEntry(lastMenuEntry->baseWidget()))) {
- entryDialog(e);
- }
- }
-
- void
- DayView::entryDeleteMenu()
- {
- Entry *e;
-
- if (lastMenuEntry &&
- (e = findEntry(lastMenuEntry->baseWidget()))) {
- deleteEntry(e);
- scroll->reannotateScrollBar();
- }
- }
-
- /**********************************************************************/
-
- DayView::DayView( VCal *o, const char *docName)
- : VkWindow(docName)
- {
- owner = o;
-
- numSlots = 0;
- _day = _month = _year = 0;
- _lastTime = 0;
- _info = NULL;
- _repeating = NULL;
- timeInterval = thePreferences->gridLength();
- subdivisions = thePreferences->apptSubdiv();
- timeSlotSnap = thePreferences->snapInterval();
- restricted = thePreferences->restricted();
- restrictStart = 60*thePreferences->restrictStart();
- restrictEnd = 60*thePreferences->restrictStop();
- defaultLength = thePreferences->apptLength();
-
- troughGC = NULL;
- timeGC = NULL;
- dayPrev = NULL;
- header = NULL;
- entryPopup = NULL;
- repeatingEntryPopup = NULL;
- lastMenuEntry = NULL;
- }
-
- DayView::~DayView()
- {
- if (entryPopup) {
- delete entryPopup;
- }
- if (repeatingEntryPopup) {
- delete repeatingEntryPopup;
- }
- if (troughGC) {
- XtReleaseGC(form, troughGC);
- }
- if (timeGC) {
- XtReleaseGC(form, timeGC);
- }
- }
-
- const char *
- DayView::className()
- {
- return "DayView";
- }
-